package com.base.invoke.third;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * java 调用Windows命令
 */
public class JavaExecWin {


    public static void test() throws IOException {
        Runtime runtime = Runtime.getRuntime();
        Process process = runtime.exec("cmd /c start dir");

        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        StringBuilder stringBuilder = new StringBuilder();
        String line = "";
        while ((line = reader.readLine()) != null) {
            stringBuilder.append(line);
        }
        System.out.println("stringBuilder = " + stringBuilder);

    }

    public static void main(String[] args) throws IOException {
        test();
    }
}
